package com.gel.codegeneration.core.saver;

import com.gel.codegeneration.ai.model.entity.HtmlCodeResult;
import com.gel.codegeneration.ai.model.entity.MultiFileResult;
import com.gel.codegeneration.ai.model.enums.CodeGenTypeEnum;
import com.gel.codegeneration.common.enums.ErrorCode;
import com.gel.codegeneration.convention.exception.BusinessException;

import java.io.File;

/**
 * @BelongsProject: code-generation-platform
 * @BelongsPackage: com.gel.codegeneration.core.saver
 * @Author: gel
 * @CreateTime: 2025-08-22  16:12
 * @Description: TODO
 * @Version: 1.0
 */
public class CodeSaveExecutor {
    private  static HtmlCodeFileSaveTemplate htmlCodeFileSaveTemplate = new HtmlCodeFileSaveTemplate();
    private  static MultiFileCodeFileSaveTemplate multiFileCodeFileSaveTemplate = new MultiFileCodeFileSaveTemplate();
    public static File executeSaver(Object  result, CodeGenTypeEnum codeGenType, Long appId){
        return  switch (codeGenType){
            case HTML->
                    htmlCodeFileSaveTemplate.saveCode((HtmlCodeResult) result,appId);
            case MULTI_FILE->
                    multiFileCodeFileSaveTemplate.saveCode((MultiFileResult) result,appId);
            default -> {
                String errorMsg = "不支持的代码生成类型：" + codeGenType.getValue();
                throw new BusinessException(ErrorCode.SYSTEM_ERROR,errorMsg);
            }
        };
    }
}
